home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / VLA_FONT.ZIP / VCH2FNT.ASM < prev    next >
Assembly Source File  |  1993-09-28  |  8KB  |  325 lines

  1.     IDEAL
  2.     DOSSEG
  3.     MODEL SMALL
  4.     STACK 200h
  5.     CODESEG
  6.     p386n
  7.     ASSUME  CS:@CODE, DS:@CODE
  8. ───────────────────────────────────────────────────────────────────────────    
  9.     INCLUDE "PRINTSUB.inc"
  10.     INCLUDE "MCLSUB.INC"
  11. ────────────────────────────────────────────────────────────────────────────
  12. STRUC VCH_Header
  13.     Id      db  "VLACH"
  14.     From    db  ?
  15.     X       db  ?
  16.     Y       db  ?
  17.     NumChr  db  ?
  18. ENDS
  19.  
  20. STRUC FNT_Header
  21.     Id          db  "VLAFNT"
  22.     X           db  1           ;widths in BYTES (8 pixels)
  23.     Y           db  8
  24.     NumChr      db  ?
  25.     StartChr    db  " "         ;char to start with
  26. ENDS
  27. ────────────────────────────────────────────────────────────────────────────
  28. FileName_VCH    db  130 dup (0)
  29. Extension_VCH   db  ".VCH",0
  30. Handle_VCH      dw  ?
  31.  
  32. FileName_FNT    db  130 dup (0)
  33. Extension_Fnt   db  ".FNT",0
  34. Handle_FNT      dw  ?
  35.  
  36. Dsp_Seg         dw  ?
  37. VCH_Seg         dw  ?
  38. FNT_Seg         dw  ?
  39.  
  40. Credits         db  "VCH to FNT converter written by Draeden of VLA!"
  41.                 db  13,10,10,0
  42.  
  43. MSG_OpenError   db  "Error loading VCH file.",13,10,0
  44. MSG_OverWrite   db  "FNT file already exists, replace? (Y/N)",13,10,0
  45. MSG_CreateError db  "Failed to create FNT file.",13,10,0
  46. MSG_WriteError  db  "Failed to write the FNT file!?",13,10,0
  47. MSG_Written     db  " was successfully written.",0
  48.  
  49. VCHHead         VCH_Header <>
  50. FNTHead         FNT_Header <>
  51. ───────────────────────────────────────────────────────────────────────────
  52.     ──────────────────────────────────────────────────────────────────
  53.     ;This routine opens the VCH file
  54.     ;Returns    CF = 0 = Success! VCH file opened
  55.     ;           CF = 1 = Failed to open file
  56.     ──────────────────────────────────────────────────────────────────
  57. PROC Open_VCH NEAR
  58.     pusha
  59.     push    ds
  60.  
  61.     mov     ax,cs
  62.     mov     ds,ax
  63.     mov     dx,offset FileName_VCH
  64.     mov     ax,3d00h                ;open file
  65.     int     21h
  66.     jc      @@END
  67.     mov     [Handle_VCH],ax
  68.     clc
  69.  
  70. @@END:
  71.     pop     ds
  72.     popa
  73.     ret
  74. ENDP
  75.     ──────────────────────────────────────────────────────────────────
  76.     ;This routine creates (safely) the FNT file
  77.     ;Returns    CF = 0 = Success! was able to create file
  78.     ;           CF = 1 = Failed!  could not create FNT file
  79.     ──────────────────────────────────────────────────────────────────
  80. PROC Create_FNT NEAR
  81.     pusha
  82.     push    ds
  83.     mov     ax,cs
  84.     mov     ds,ax
  85.  
  86.     mov     dx,offset FileName_FNT
  87.     mov     ax,5b00h                ;create file (safe)
  88.     xor     cx,cx
  89.     int     21h
  90.     jc      @@FileError1
  91.     mov     [Handle_FNT],ax
  92.     clc                         ;No error occured
  93.     jmp     @@End
  94.  
  95. @@FileError1:
  96.     mov     si,offset MSG_Overwrite
  97.     call    PrintZ
  98.     call    YesNo
  99.     jnc     @@Abort
  100.  
  101.     mov     dx,offset FileName_FNT
  102.     mov     ax,3c00h                ;create file (unsafe)
  103.     xor     cx,cx
  104.     int     21h
  105.     jc      @@Abort
  106.     mov     [Handle_FNT],ax
  107.     clc                         ;No error occured
  108.     jmp     @@End
  109.  
  110. @@Abort:
  111.     stc
  112. @@END:
  113.     pop     ds
  114.     popa
  115.     ret
  116. ENDP
  117.     ──────────────────────────────────────────────────────────────────
  118.     ;Closes VCH file... nothing can go wrong that we care about...
  119.     ──────────────────────────────────────────────────────────────────
  120. PROC Close_VCH NEAR
  121.     push    ax bx
  122.  
  123.     mov     bx,[cs:HANDLE_VCH]
  124.     mov     ah,3eh
  125.     int     21h
  126.  
  127.     pop     bx ax     
  128.     ret
  129. ENDP
  130.     ──────────────────────────────────────────────────────────────────
  131.     ;Closes FNT file... nothing can go wrong that we care about...
  132.     ──────────────────────────────────────────────────────────────────
  133. PROC Close_FNT NEAR
  134.     push    ax bx
  135.  
  136.     mov     bx,[cs:HANDLE_FNT]
  137.     mov     ah,3eh
  138.     int     21h
  139.  
  140.     pop     bx ax     
  141.     ret
  142. ENDP
  143.     ──────────────────────────────────────────────────────────────────
  144.     ; Converts the VCH to FNT
  145.     ──────────────────────────────────────────────────────────────────
  146. PROC Convert_VCH2FNT NEAR
  147.     pusha
  148.     push    ds es
  149.     mov     ax,cs
  150.     mov     ds,ax
  151.  
  152.     mov     al,[VCHhead.NumChr]
  153.     mov     [FNThead.NumChr],al
  154.     mov     al,[VCHhead.From]
  155.     mov     [FNThead.StartChr],al
  156.     mov     [FNThead.X],1           ;that's 8 pixels wide
  157.     mov     al,[VCHhead.Y]
  158.     mov     [FNThead.Y],al
  159.  
  160.     xor     si,si
  161.     mov     di,si
  162.     mov     es,[FNT_Seg]
  163.     mov     ds,[VCH_Seg]
  164.  
  165.     mov     ch,[cs:FNThead.NumChr]
  166.     mov     cl,[cs:FNThead.Y]
  167.     xor     ah,ah
  168.     mov     dl,8
  169. @@CLoop:
  170.     shl     ah,1
  171.     lodsb
  172.     or      al,al
  173.     je      @@Tis0
  174.     or      ah,1
  175. @@Tis0:
  176.  
  177.     dec     dl
  178.     jne     @@Cloop
  179.     mov     dl,8
  180.     mov     al,ah
  181.     stosb
  182.     xor     ah,ah
  183.  
  184.     dec     cl
  185.     jne     @@CLoop
  186.  
  187.     mov     cl,[cs:FNThead.Y]
  188.     dec     ch
  189.     jne     @@Cloop
  190.     
  191.     pop     es ds
  192.     popa
  193.     ret
  194. ENDP
  195.     ──────────────────────────────────────────────────────────────────
  196.     ; Writes the FNT header and all the FNT data
  197.     ──────────────────────────────────────────────────────────────────
  198. PROC Write_FNT NEAR
  199.     pusha
  200.     push    ds
  201.  
  202.     mov     ax,cs
  203.     mov     ds,ax
  204.     
  205.     mov     bx,[HANDLE_FNT]             ;save FNT header
  206.     mov     cx,(size FNT_HEADER)
  207.     mov     ah,40h
  208.     mov     dx,offset FNThead
  209.     int     21h
  210.     jc      @@FileError
  211.  
  212.     mov     al,[cs:FNTHead.NumChr]
  213.     mov     ah,[cs:FNTHead.Y]
  214.     mul     ah
  215.     movzx   cx,[cs:FNTHead.X]
  216.     mul     cx
  217.     mov     cx,ax
  218.     mov     ds,[cs:FNT_Seg]
  219.     mov     dx,dx                       ;save off FNT data
  220.     mov     ah,40h
  221.     int     21h
  222.     clc
  223.  
  224. @@FileError:
  225.     pop     ds
  226.     popa
  227.     ret
  228. ENDP
  229.     ──────────────────────────────────────────────────────────────────
  230.     ; Reads in the VCH header and all the character data
  231.     ──────────────────────────────────────────────────────────────────
  232. PROC Read_VCH NEAR
  233.     pusha
  234.     push    ds
  235.     mov     ax,cs
  236.     mov     ds,ax
  237.     mov     bx,[Handle_VCH]
  238.     mov     cx,(size VCH_Header)
  239.     mov     dx,offset VCHhead
  240.     mov     ah,3fh
  241.     int     21h
  242.  
  243.     mov     ds,[VCH_seg]
  244.     mov     al,[cs:VCHHead.NumChr]
  245.     mov     ah,[cs:VCHHead.X]
  246.     cmp     ah,8
  247.     jne     @@Fail
  248.  
  249.     mul     ah
  250.     movzx   cx,[cs:VCHHead.Y]
  251.     mul     cx
  252.     xor     dx,dx
  253.     mov     cx,ax
  254.     mov     ah,3fh
  255.     int     21h             ;read in all of the stuff
  256.     clc
  257.     jmp     short @@Done
  258.  
  259. @@Fail:
  260.     stc
  261. @@Done:
  262.     pop     ds
  263.     popa
  264.     ret
  265. ENDP
  266. ────────────────────────────────────────────────────────────────────────────
  267. Start:
  268.     mov     ax,cs
  269.     mov     ds,ax
  270.     mov     [Dsp_Seg],es
  271.  
  272.     mov     bx,ss
  273.     mov     ax,sp
  274.     add     ax,15
  275.     shr     ax,4
  276.     add     bx,ax
  277.     mov     [VCH_Seg],bx
  278.     add     bx,1000h
  279.     mov     [FNT_Seg],bx
  280.  
  281.     mov     es,[Dsp_Seg]
  282.     mov     dx,offset FileName_VCH
  283.     mov     bx,offset Extension_VCH
  284.     mov     bp,1                        ;override extension
  285.     call    GetCommandLine
  286.     mov     dx,offset FileName_FNT
  287.     mov     bx,offset Extension_FNT
  288.     call    GetCommandLine
  289.  
  290.     call    Open_VCH
  291.     jnc     @@NoFileError
  292.     
  293.     mov     si,offset MSG_OpenError
  294.     call    PrintZ
  295.     mov     al,1
  296.     jmp     ExitProg
  297.  
  298. @@NoFileError:
  299.     call    Create_FNT
  300.     jnc     @@NoCreateError
  301.     call    Close_VCH
  302.     mov     si,offset MSG_CreateError
  303.     call    PrintZ
  304.     mov     al,2
  305.     jmp     ExitProg
  306.  
  307. @@NoCreateError:
  308.     call    Read_VCH
  309.     call    Convert_VCH2FNT
  310.     call    Write_FNT
  311.     call    Close_FNT
  312.     call    Close_VCH
  313.  
  314.     mov     si,offset FileName_FNT
  315.     call    PrintZ
  316.     mov     si,offset MSG_Written
  317.     call    PrintZ
  318.     xor     al,al
  319.  
  320. ExitProg:
  321.     mov     ah,4ch
  322.     int     21h
  323. END START
  324.  
  325.